/**
 * 条件搜索
 * @param url
 */
function search(url) {
    openPage(url + "?" + returnSearch());
}
/**
 * 返回搜索条件
 * @returns {string}
 */
function returnSearch() {
    var param = 'giftType=' + $('#giftType').val();
    param += '&status=' + $('#status').val();
    param += '&resultSort=' + $('#resultSort').val();
    param += '&orderType=' + $('#orderType').val();
    param += '&pageNumber=' + $('#pageNumber').val();
    param += '&pageSize=' + $('#pageSize').val();
    return param;
}
/**
 * 新增s
 * @param url
 */
function toTaskInfo(url, taskId) {
    openPage(url + "?taskId=" + taskId + "&" + returnSearch());
}

/**
 * 批量修改
 */
function batchUpdate(url, tableId, status) {
    var checks = $('#' + tableId).find(':checkbox');
    var ids = "";
    $.each(checks, function () {
        if (this.checked) {
            ids += this.name + ",";
        }
    })
    $.ajax({
        url: url,
        type: "POST",
        data: {"ids": ids, 'status': status},
        success: function (data) {
            if (data.status) {
                alert(data.message);
                window.location.reload(true);
            }
        }
    });
}

//保存新增/修改
function saveTask() {
    var data = {
        'id': $('#taskId').val(),
        'giftType': $('#giftType').val(),
        'giftName': $('#giftName').val(),
        'taskOrder': $('#taskOrder').val(),
        'taskDesc': $('#taskDesc').val(),
        'requireType': $('#requireType').val(),
        'requireCount': $('#requireCount').val(),
        'resetDays': $('#resetDays').val(),
        'prizeType1': $('#prizeType1').val(),
        'prizeCount1': $('#prizeCount1').val(),
        'prizeType2': $('#prizeType2').val(),
        'prizeCount2': $('#prizeCount2').val(),
        'prizeType3': $('#prizeType3').val(),
        'prizeCount3': $('#prizeCount3').val()
    }
    $.ajax({
        url: "/view/task/saveOrUpdateTaskInfo",
        type: "POST",
        dataType: "json",
        data: data,
        success: function (data) {
            if (data.status === 200) {
                window.location.href = "/view/task/searchTaskList?pageNumber=" + GetQueryString("pageNumber")
                    + "&pageSize=" + GetQueryString("pageSize")
                    + "&giftType=" + GetQueryString("giftType")
                    + "&status=" + GetQueryString("status")
                    + "&resultSort=" + GetQueryString("resultSort")
                    + "&orderType=" + GetQueryString("orderType");
            }
        },
    });
}

function cancles() {
    openPage("/view/task/searchTaskList?pageNumber=" + GetQueryString("pageNumber")
        + "&pageSize=" + GetQueryString("pageSize")
        + "&giftType=" + GetQueryString("giftType")
        + "&status=" + GetQueryString("status")
        + "&resultSort=" + GetQueryString("resultSort")
        + "&orderType=" + GetQueryString("orderType"));
}
